Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Github contribution error #650

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Yemaneberhan-Lemma
Copy link
Contributor

Handling the issue

Copy link
Member

@hussainweb hussainweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the backoff algorithm is good, you are doing a lot here for a simple fix. Because this is likely to be stuck in review, I'd encourage you to create another PR with the minimal fix so that we can merge it quickly. After that, we can talk about other improvements, including the back-off algorithm in this PR.

$config = $config_factory->get('ct_github.settings');
$token = $config->get('github_auth_token');
$client = new Client();
$client->authenticate($token, NULL, AuthMethod::ACCESS_TOKEN);
$client = (strlen($token) === 40) ? (new Client())->authenticate($token, NULL, AuthMethod::ACCESS_TOKEN) : NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all tokens are 40 characters in length. Fine-grained tokens are longer.

@@ -40,13 +41,14 @@ class GithubQuery {
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
* The injected cache backend service.
*/
public function __construct(ConfigFactory $config_factory, CacheBackendInterface $cacheBackend) {
public function __construct(ConfigFactory $config_factory, CacheBackendInterface $cacheBackend, LoggerChannelFactoryInterface $loggerFactory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra whitespace. This should have been caught by the CI. This is another issue but let's not introduce this here.

Comment on lines +151 to +154
if ($e->getMessage() === 'Bad credentials') {
$this->logger->error('GitHub API error: Bad credentials. Please check the credentials.');
return NULL;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it likely that we will get bad credentials here? Shouldn't this have been caught in authenticate method itself?


// Handle other errors with backoff
$retryCount++;
$this->logger->warning("GitHub API request failed. Retry $retryCount/$maxRetries. Error: " . $e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not log this at warning when we are going to try again. We can log this at info or notice level maybe.

Comment on lines +69 to +73
if($userContributions){
$issues = array_map(function ($issue) {
return new Issue($issue['title'], $issue['url']);
}, $userContributions['data']['user']['issues']['nodes']);
return $issues;
return $issues;}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace error. Again this should have been caught in the CI.

Comment on lines +93 to +95
if ($plugin_id === "github") {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a code smell. The ct_manager should not have to know about ct_github.

@hussainweb
Copy link
Member

@Yemaneberhan-Lemma, this needs to be rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants